package calorie.com.calorie.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.AppCompatImageView;
import android.view.View;
import android.widget.TextView;

import calorie.com.calorie.R;


/**
 * Created with IntelliJ IDEA.
 * UserBean: ZhaoShiDong
 * Date: 2018/9/18
 * Time: 18:09
 */
public class CustomTwoSelectDialog extends Dialog implements View.OnClickListener {

    View vETH;
    View vAECE;


    AppCompatImageView ivETH;
    AppCompatImageView ivAECE;

    private int nowCurrency;
    private String strOne, strTwo, strTmp;
    private TextView tvOne, tvTwo;
    private int tempInt;


    public int getNowCurrency() {
        return nowCurrency;
    }

    public void setNowCurrency(int currency) {
        this.nowCurrency = currency;
    }

    private OnCurrencyClickListener onCurrencyClickListener;

    public void setOnCurrencyClickListener(OnCurrencyClickListener onCurrencyClickListener) {
        this.onCurrencyClickListener = onCurrencyClickListener;
    }

    public CustomTwoSelectDialog(Context context, String one, String two, int tmp) {
        super(context, R.style.MypPaypasswordDialog);
        this.strOne = one;
        this.strTwo = two;
        this.tempInt = tmp;
    }

    public CustomTwoSelectDialog(Context context, String tmp) {
        super(context, R.style.MypPaypasswordDialog);
        this.strTmp = tmp;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.dialog_currency_select_two);
        //按空白处可取消动画
        setCanceledOnTouchOutside(true);

        initView();

        initEvent();
    }

    public void initView() {
        vETH = findViewById(R.id.v_eth);
        vAECE = findViewById(R.id.v_aece);

        ivETH = findViewById(R.id.iv_eth);
        ivAECE = findViewById(R.id.iv_aece);

        tvOne = findViewById(R.id.tv_eth);
        tvTwo = findViewById(R.id.tv_aece);
//        tvOne.setText(strOne);
//        tvTwo.setText(strTwo);

        if (nowCurrency == 0) {
            ivETH.setVisibility(View.VISIBLE);
            ivAECE.setVisibility(View.INVISIBLE);

        } else {
            ivAECE.setVisibility(View.VISIBLE);
            ivETH.setVisibility(View.INVISIBLE);
        }
    }

    public void initEvent() {
        vETH.setOnClickListener(this);
        vAECE.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        if (onCurrencyClickListener != null) {
            switch (view.getId()) {
                case R.id.v_eth:
                    onCurrencyClickListener.onSelect("CAL");
                    ivETH.setVisibility(View.VISIBLE);
                    ivAECE.setVisibility(View.INVISIBLE);
                    break;
                case R.id.v_aece:
                    onCurrencyClickListener.onSelect("激活券");
                    ivAECE.setVisibility(View.VISIBLE);
                    ivETH.setVisibility(View.INVISIBLE);
                    break;
            }
        }
    }

    public interface OnCurrencyClickListener {
        void onSelect(String currency);
    }
}
